/*
 *
 * Copyright (c) 2001-2016 泛微软件.
 * 泛微协同商务系统,版权所有.
 * 
 */
package com.engine.workplan.web;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.api.doc.upload.web.FileUploadAction;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.workplan.cmd.calendar.ExportCalendarViewListUtil;
import com.engine.workplan.service.WorkPlanCalendarService;
import com.engine.workplan.service.impl.WorkPlanCalendarServiceImpl;
import org.apache.commons.lang.StringUtils;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * 日程日历相关接口
 * @author lmx
 *
 */
public class WorkPlanCalendarAction {

    /**
     * 获取服务
     * @param request
     * @param response
     * @return
     */
    private WorkPlanCalendarService getService(HttpServletRequest request, HttpServletResponse response) {
        User user = HrmUserVarify.getUser(request, response);// 需要增加的代码
        return getService(user);
    }

    /**
     * 获取服务
     * @param user
     * @return
     */
    private WorkPlanCalendarService getService(User user) {
        return ServiceUtil.getService(WorkPlanCalendarServiceImpl.class, user);
    }

    /**
     * 获取日程日历基础信息
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getBaseData")
    @Produces(MediaType.TEXT_PLAIN)
    public String getBaseData(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getBaseData(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 保存日历视图
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/setViewType")
    @Produces(MediaType.TEXT_PLAIN)
    public String setViewType(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).setViewType(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 日历页面编辑
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/editCalendarItem")
    @Produces(MediaType.TEXT_PLAIN)
    public String editCalendarItem(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).editCalendarItem(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 日历页面快速编辑
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/editCalendarItemQuick")
    @Produces(MediaType.TEXT_PLAIN)
    public String editCalendarItemQuick(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).editCalendarItemQuick(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 导入日程
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/importExcel")
    @Produces(MediaType.TEXT_PLAIN)
    public String importExcel(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            Map<String, Object> params=ParamUtil.request2Map(request);
            params.put("requestObj",request);
            apidatas.putAll(getService(user).importExcel(params));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 记录导入文档fileid
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/addExcelFileid")
    @Produces(MediaType.TEXT_PLAIN)
    public String addExcelFileid(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            //先调用上传文件action，然后再记录
            FileUploadAction fileUploadAction = new FileUploadAction();
            String fileRet = fileUploadAction.uploadFile(request,response);
            JSONObject jsonObject = JSONObject.parseObject(fileRet);
            if(Util.getIntValue(jsonObject.get("status")+"") == 1){
                Map parmas = ParamUtil.request2Map(request);
                parmas.putAll((Map)jsonObject.get("data"));
                apidatas.putAll(getService(user).addExcelFileid(parmas));
                apidatas.putAll(jsonObject);
                apidatas.put("status",true);
                apidatas.put("api_status", true);
            }else{
                return fileRet;
            }
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 添加关注
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/addAttention")
    @Produces(MediaType.TEXT_PLAIN)
    public String addAttention(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            //执行添加操作
            getService(user).addAttention(ParamUtil.request2Map(request));

            //不论添加是否成功，都再获取一次关注者信息给前端
            apidatas.putAll(getService(user).getAttentionData(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 获取关注者信息
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getAttentionData")
    @Produces(MediaType.TEXT_PLAIN)
    public String getAttentionData(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getAttentionData(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 删除关注
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/delAttention")
    @Produces(MediaType.TEXT_PLAIN)
    public String delAttention(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            //执行删除操作
            getService(user).delAttention(ParamUtil.request2Map(request));

            //不论添加是否成功，都再获取一次关注者信息给前端
            apidatas.putAll(getService(user).getAttentionData(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 获取指定日期所在周的日程总数
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getWorkPlanWeekCount")
    @Produces(MediaType.TEXT_PLAIN)
    public String getWorkPlanWeekCount(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getWorkPlanWeekCount(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 我的日程
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/MyCalendar")
    @Produces(MediaType.TEXT_PLAIN)
    public String getMyCalendar(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getMyCalendar(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 全部日程
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/AllCalendar")
    @Produces(MediaType.TEXT_PLAIN)
    public String getAllCalendar(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getAllCalendar(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


    /**
     * 展示日程数量
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getWorkPlanCount")
    @Produces(MediaType.TEXT_PLAIN)
    public String getWorkPlanCount(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getWorkPlanCount(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas);
    }


    /**
     * 日程一览表数据接口
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getCalendarData")
    @Produces(MediaType.TEXT_PLAIN)
    public String getCalendarData(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getCalendarData (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 日程一览表导出
     * 导出日程清单
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/exportExcelList")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)//返回方式为流
    public Response exportExcel(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(null==user){
                return null;
            }
            ExportCalendarViewListUtil export=new ExportCalendarViewListUtil(user);
            InputStream input =export.exportExcel(request, response);
            String filename = Util.null2String(request.getParameter("filename"),export.getDefaultName());
            String ua = request.getHeader("User-Agent").toLowerCase();
            //这里为了兼容mac系统，文件中文名乱码问题。
            if (ua.indexOf("macintosh") > -1 && ua.indexOf("chrome") < 0) {
                filename =new String(filename.getBytes(), "iso8859-1");
            }else{
                filename = java.net.URLEncoder.encode(filename, "UTF-8");
            }
            filename = StringUtils.replace(filename, "/", "");
            filename = StringUtils.replace(filename, "%2F", "");
            filename = StringUtils.replace(filename, "+", "%20");
            filename = Util.formatMultiLang(filename, user.getLanguage()+"") + ".xls";

            return Response
                    .ok(input)
                    .header("Content-disposition", "attachment;filename=" + filename)
                    .header("Cache-Control", "no-cache").build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 日程一览表导出
     * 导出对应样式的Excel
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/exportExcel4Html")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)//返回方式为流
    public Response exportExcel4Html(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(null==user){
                return null;
            }
            Map params = ParamUtil.request2Map(request);
            params.put("request",request);
            Map apidatas=getService(user).exportExcel4Html (params);
            if(null==apidatas){
                return null;
            }
            InputStream input=(InputStream)apidatas.get("InputStream");
            String fileName=Util.null2String(apidatas.get("filename"));

            return Response
                    .ok(input)
                    .header("Content-disposition", "attachment;filename=" + fileName)
                    .header("Cache-Control", "no-cache").build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 所有下属接口
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getUnderlining")
    @Produces(MediaType.TEXT_PLAIN)
    public String getUnderlining(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getUnderlining (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

	/**
     * 更新关注
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateAttention")
    @Produces(MediaType.TEXT_PLAIN)
    public String updateAttention(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).updateAttention (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

	/**
     * 一周日程安排
     * 获取分组信息
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getWorkPlanWeekGroupSelect")
    @Produces(MediaType.TEXT_PLAIN)
    public String getWorkPlanWeekGroupSelect(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getWorkPlanWeekGroupSelect (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

	/**
     * 一周日程安排
     * 数据信息
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getWorkPlanWeekData")
    @Produces(MediaType.TEXT_PLAIN)
    public String getWorkPlanWeekData(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getWorkPlanWeekData (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 一周日程安排
     * 导出对应样式的Excel
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/exportWeekPlanExcel4Html")
    @Produces(MediaType.APPLICATION_OCTET_STREAM)//返回方式为流
    public Response exportWeekPlanExcel4Html(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(null==user){
                return null;
            }
            Map params = ParamUtil.request2Map(request);
            params.put("request",request);
            Map apidatas=getService(user).exportWeekPlanExcel4Html (params);
            if(null==apidatas){
                return null;
            }
            InputStream input=(InputStream)apidatas.get("InputStream");
            String fileName=Util.null2String(apidatas.get("filename"));

            return Response
                    .ok(input)
                    .header("Content-disposition", "attachment;filename=" + fileName)
                    .header("Cache-Control", "no-cache").build();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 更新一周日程安排查看样式
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/updateWeekViewType")
    @Produces(MediaType.TEXT_PLAIN)
    public String updateWeekViewType(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).updateWeekViewType (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取语义识别客户端接口状态
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/getSemanticStatus")
    @Produces(MediaType.TEXT_PLAIN)
    public String getSemanticStatus(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).getSemanticStatus (ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 同步ews数据到oa
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @POST
    @Path("/syncEwsToWP")
    @Produces(MediaType.TEXT_PLAIN)
    public String syncEwsToWP(@Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try {
            User user = HrmUserVarify.getUser(request, response);
            if(user==null){
                apidatas.put("api_status", false);
                return JSONObject.toJSONString(apidatas);
            }
            apidatas.putAll(getService(user).syncEwsToWP(ParamUtil.request2Map(request)));
            apidatas.put("api_status", true);
        } catch (Exception e) {
            e.printStackTrace();
            apidatas.put("api_status", false);
            apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
        }
        return JSONObject.toJSONString(apidatas, SerializerFeature.DisableCircularReferenceDetect);
    }




}
